<include file="Public/header"/>
<div class="row">
	<div class="col-md-12">
		<div class="ibox-title">权限管理</div>
		<div class="ibox-content">
			<form class="layui-form" autocomplete="off">
				<div class="layui-form-item">
					<label class="layui-form-label">权限列表：</label>
					<foreach name="menus" item="vo" key="k">
						<div class="layui-input-block">
							<input type="checkbox" name="menu[<{$vo.id}>]" lay-skin="primary" value="<{$vo['id']}>" title="<{$vo.title}>" class="level_one" <?php if(in_array($vo['id'],$rulesArr)){echo "checked";} ?>>
							<foreach name="vo[$vo['id']]" item="v">
								<div class="layui-input-block">
									<input type="checkbox" name="menu[<{$v.id}>]" lay-skin="primary" title="<{$v.title}>" value="<{$v['id']}>" class="level_two" <?php if(in_array($v['id'],$rulesArr)){echo "checked";} ?>>
									<div class="layui-input-block">
										<foreach name="v[$v['id']]" item="v1">
											<input type="checkbox" name="menu[<{$v1.id}>]" lay-skin="primary" title="<{$v1.title}>" value="<{$v1['id']}>" class="level_three" <?php if(in_array($v1['id'],$rulesArr)){echo "checked";} ?>>
										</foreach>
									</div>
								</div>
							</foreach>
						</div>
					</foreach>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="auth">立即提交</button>
					</div>
				</div>
				<input type="hidden" name="roleid" value="<{$_GET['roleid']}>">
			</form>
		</div>
</div>
</div>
<include file="Public/footer"/>
<script>
    layui.use(['layer','form'], function() {
        var form = layui.form,
            $ = layui.jquery;
        //选中
        $('.layui-form-checkbox').on('click', function (e){
            var children = $(this).parent('.layui-input-block').find('.layui-form-checkbox');
            var input = $(this).parent('.layui-input-block').find('input');

            if($(this).prev('input').hasClass('level_three')){
                if($(this).hasClass('layui-form-checked') == true){
                    $(this).addClass('layui-form-checked')
                    $(this).prev('input').prop('checked',true);
                }else{
                    $(this).removeClass('layui-form-checked');
                    $(this).prev('input').prop('checked',false);
                }
            }else{
                if($(this).hasClass('layui-form-checked') == true){
                    children.addClass('layui-form-checked')
                    input.prop('checked',true);
                }else{
                    children.removeClass('layui-form-checked');
                    input.prop('checked',false);
                }
            }
        })
        //监听提交
        form.on('submit(auth)', function(data){
            var menu_ids = data.field;
            var url = "<{:U('Auth/ruleGroup')}>";
            $.post(url,menu_ids,function(data){
                if(data.status == 'error'){
                    layer.msg(data.msg,{icon: 5});//失败的表情
                    return;
                }else{
                    layer.msg(data.msg, {
                        icon: 6,//成功的表情
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        history.go(-1);
                    });
                }
            })
            return false;//阻止表单跳转
        });
    });
</script>
</body>
</html>